package com.cqw.config;

import org.springframework.context.annotation.Configuration;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-08-25 16:11
 * @Description: jackson配置
 */
@Configuration
public class JacksonConfig {

//    @Resource
//    private IdSerializer idSerializer;
//
//    @Resource
//    private IdDeserializer idDeserializer;

//
//    @Bean
//    public ObjectMapper objectMapper() {
//        ObjectMapper objectMapper = new ObjectMapper();
//        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//        //不注释,会导致swagger报错
//        //objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//        //关闭日期序列化为时间戳的功能
//        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
//        //关闭序列化的时候没有为属性找到getter方法,报错
//        objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
//        //关闭反序列化的时候，没有找到属性的setter报错
//        objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//        //序列化的时候序列对象的所有属性
//        objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
//        //反序列化的时候如果多了其他属性,不抛出异常
//        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//        //如果是空对象的时候,不抛异常
//        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
//        SimpleModule simpleModule = new SimpleModule();
//        //json值序列化
//        //simpleModule.addSerializer(Long.class, idSerializer);
//        //json值反序列化
//        simpleModule.addDeserializer(Long.class, idDeserializer);
//        //json键序列化
//        //simpleModule.addKeySerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE);
//        //json键反序列化
//        //simpleModule.addKeyDeserializer(LocalDateTime.class, LocalDateTimeKeyDeserializer.INSTANCE);
//        objectMapper.registerModule(simpleModule);
//        return objectMapper;
//    }


}
